package com.eduhzy.ttw.clazz.di.module;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.clazz.R;
import com.eduhzy.ttw.clazz.mvp.contract.AddReviewContract;
import com.eduhzy.ttw.clazz.mvp.model.AddReviewModel;
import com.eduhzy.ttw.clazz.mvp.model.entity.ClazzAddScore;
import com.eduhzy.ttw.commonres.utils.RxUtil;
import com.eduhzy.ttw.commonsdk.decoration.GridSpacingItemDecoration;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;
import com.jess.arms.di.scope.ActivityScope;

import java.util.ArrayList;
import java.util.List;

import dagger.Module;
import dagger.Provides;

/**
 * @author xubo
 * @date 2018-12-5 12:20:37
 */
@Module
public class AddReviewModule {
    private AddReviewContract.View view;

    /**
     * 构建AddReviewModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public AddReviewModule(AddReviewContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    AddReviewContract.View provideAddReviewView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    AddReviewContract.Model provideAddReviewModel(AddReviewModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    List<ClazzAddScore> provideLists() {
        return new ArrayList<>();
    }

    @ActivityScope
    @Provides
    BaseQuickAdapter<ClazzAddScore, AutoBaseViewHolder> providerAdapter(List<ClazzAddScore> lists) {
        return new BaseQuickAdapter<ClazzAddScore, AutoBaseViewHolder>(R.layout.clazz_rv_item_add_review, lists) {
            @Override
            protected void convert(AutoBaseViewHolder helper, ClazzAddScore item) {
                helper.setText(R.id.btn_score, item.getScore());
                helper.getView(R.id.btn_score).setSelected(item.isSelect());
                helper.addOnClickListener(R.id.btn_score);
            }
        };

    }

    @ActivityScope
    @Provides
    RecyclerView.LayoutManager provideLayoutManager() {
        return new GridLayoutManager(view.getActivity(), 5){
            @Override
            public boolean  canScrollVertically(){
                return false;
            }
        };
    }

    @ActivityScope
    @Provides
    GridSpacingItemDecoration provideDecoration() {
        return new GridSpacingItemDecoration(5, RxUtil.getAutoWidth(view.getActivity(), 20), true);
    }

}